package operator;

import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * Flink的Map算子
 * Task 相当于Spark中的stage 一个Task根据并且度可以分为多个subTask
 * 如果并行度一致 同一个job下的多个算子会形成一个算子链 在一个Task中
 */
public class MapDemo {

    public static void main(String[] args) throws Exception {
        // Flink配置
        Configuration conf = new Configuration();
        conf.setInteger("rest.port", 80);
        // 创建带Webui的Flink本地执行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI(conf);
        // 使用socket创建DataStream
        DataStreamSource<String> data = env.socketTextStream("localhost", 8888);

        // 使用map算子
        SingleOutputStreamOperator<Integer> maped = data.map(s -> Integer.parseInt(s) * 10);

        // sink
        maped.print();

        env.execute("map operator");
    }
}
